package com.qdhhxy.service;

import com.qdhhxy.entity.CarEntity;
import com.qdhhxy.entity.UserEntity;
import com.qdhhxy.mapper.CarMapper;
import com.qdhhxy.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CarMapper carMapper;
    @Override
    public String insertUser(UserEntity userEntity){
        userMapper.insertUser(userEntity);
        return "inser user";
    }

    @Override
    public UserEntity selectUserById(int id) {
        UserEntity user = userMapper.selectUserById(id);
        int stuId = user.getId();
//        System.out.println(stuId);//正确
        List<CarEntity> cars = carMapper.selectCarByStuId(stuId);
        System.out.println(cars);//没有数据
        user.setCarEntities(cars);
        return user;
    }
}
